<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/9/20 23:49
 */

namespace module\document\front\table;

use module\document\enum\DocumentPageType;
use module\document\enum\DocumentTypeEnum;
use module\document\model\Document;
use mof\enum\StatusEnum;
use mof\front\Table;
use mof\utils\ElementData;

class DocumentTable extends Table
{
    protected string $serverBaseUrl = '/{module}/admin/{table}';
    protected bool   $showSearch    = false;

    protected ElementData $typeListEd;

    protected function init(): void
    {
        parent::init();
        $typeList = DocumentTypeEnum::toDict()->toArray();
        $this->typeListEd = DocumentTypeEnum::toDict()->toElementData();

        //tabs
        $this->tabProp = 'type';
        $this->tabs = $this->typeListEd->toTabs('label', 'value');
        $this->activeTab = array_keys($typeList)[0];
    }

    protected function columnId(): array
    {
        return [
            "prop"   => 'id',
            "label"  => 'ID',
            "search" => true,
        ];
    }

//    protected function columnType(): array
//    {
//        return [
//            "prop"    => 'type',
//            "label"   => '类型',
//            "width"   => 120,
//            "type"    => "select",
//            "options" => $this->typeListEd->toSelectOptions(),
//            "visible" => false
//        ];
//    }

    protected function columnSubType(): array
    {
        return [
            "prop"        => 'sub_type',
            "label"       => '子类型',
            "width"       => 120,
            "type"        => "select",
            "options"     => DocumentPageType::toDict()->toElementData()->toSelectOptions(),
            "visibleExpr" => "type=page"
        ];
    }

    protected function columnTitle(): array
    {
        return [
            "prop"   => 'title',
            "label"  => '标题',
            "width"  => '*',
            "align"  => "left",
            "search" => true,
        ];
    }

    protected function columnStatus(): array
    {
        return [
            "prop"    => 'status',
            "label"   => '状态',
            "width"   => 100,
            "type"    => "select",
            "options" => StatusEnum::toDict()->toElementData()->toSelectOptions(),
            "search"  => true
        ];
    }

    protected function columnCreateAt(): array
    {
        return [
            "prop"  => 'create_at',
            "label" => '创建时间',
            "type"  => 'datetime'
        ];
    }

    protected function columnUpdateAt(): array
    {
        return [
            "prop"  => 'update_at',
            "label" => '更新时间',
            "type"  => 'datetime'
        ];
    }
}